//
//  ViewController.m
//  Test
//
//  Created by jingyao on 2017/12/6.
//  Copyright © 2017年 jingyao. All rights reserved.
//

#import "ViewController.h"
#import "DraggableCardView.h"
#import "CardData.h"
#import "ContainerView.h"
#import "HeadView.h"
#import "Head2View.h"
#import "ContainerModel.h"
#import "WeatherViewController.h"
#import "Global.h"
#import "ZJYDelegates.h"
#import "SaoMaViewController.h"

@interface ViewController ()<UIScrollViewDelegate, UIGestureRecognizerDelegate>

@property (nonatomic, strong) HeadView *headerView;
@property (nonatomic, strong) HeadView *headerView_2;
@property (nonatomic, strong) Head2View *header2View;
@property (nonatomic, strong) ContainerView *containerView;
@property (nonatomic, strong) NSMutableArray *containerArray;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIScrollView *headScrollView;
@property (nonatomic, strong) UIPageControl *pageControl;
@property (nonatomic, strong) UIImageView *backgroundImgView;
@end

@implementation ViewController

#pragma mark - 生命周期方法

- (void)viewDidLoad {
    [super viewDidLoad];
   
    //添加设置页面界面方法
    [self createViews];
    self.view.backgroundColor = [UIColor whiteColor];//为调试设置
    
    //放置水平方向数据的数组初始化
    self.containerArray = [[NSMutableArray alloc] init];
    
    //判断是否有登录的token
    NSString * token = [Global getToken];
    if (!token) {
        //三个页面数据，登录前
        [self initCardDatasForThreePages];
    }else {
        //四个页面,登陆后
        [self initCardDatasForFourPages];
    }
    
    //刷新数据
    [self reloadContainers];
    
    //设置代理
    self.scrollView.delegate = self;
    
    //网络接口，请求设备状态
    //[self requestForCurtainStatus];
    //网络请求，判断是哪一个账号，请求哪一个接口
    
    
    //获取通知中心单例监听通知事件
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(dealTurnPageNotification) name:@"turnPageNotification" object:nil];
    
    //获取通知中心登陆成功事件
    NSNotificationCenter *center2 = [NSNotificationCenter defaultCenter];
    [center2 addObserver:self selector:@selector(dealLoginNotification:) name:@"loginNotification" object:nil];
    
    //点击空白处隐藏键盘
    UITapGestureRecognizer *tapCancel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCancelEvent)];
    tapCancel.delegate = self;
    [self.view addGestureRecognizer:tapCancel];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"turnPageNotification" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"loginNotification" object:nil];
}

#pragma mark - container的创建和刷新

- (void)reloadContainers {
    for (UIView *view in self.scrollView.subviews) {
        if ([view isKindOfClass:[ContainerView class]]) {
            [view removeFromSuperview];//移除所有已有containerview
        }
    }
    
    for (int i = 0; i < self.containerArray.count; i++) {
        ContainerView *containerView = [self createContainerViewWithModel:self.containerArray[i]];
        //containerView.backgroundColor = [UIColor colorWithWhite:0.2 * i alpha:1.0f];//调试用
        containerView.backgroundColor = [UIColor clearColor];
        [self.scrollView addSubview:containerView];
        [containerView setTranslatesAutoresizingMaskIntoConstraints:NO];
        
        //宽，高
        [self.scrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:containerView attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f]];
        [self.scrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:containerView attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f]];
        
        //y
        [self.scrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.scrollView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:containerView attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]];
        
        //centerx上，container是scrollview的（1+2x）倍
        [self.scrollView addConstraint:[NSLayoutConstraint constraintWithItem:containerView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeCenterX multiplier:(1.0f + 2 * i) constant:0.0f]];
    }
    
    [self.view layoutIfNeeded];//为了获取正确的frame
    self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * self.containerArray.count, self.scrollView.frame.size.height);//设置ScrollView的contentsize
    
    
    [self.scrollView setContentOffset:CGPointMake(0, 0)];
    self.pageControl.currentPage = 0;
    self.pageControl.numberOfPages = self.containerArray.count;
    
}

- (ContainerView *)createContainerViewWithModel:(ContainerModel *)containerModel {
    ContainerView *containerView = [ContainerView new];
    containerView.name = containerModel.name;
    [containerView generateCardViewsWithCardArray:containerModel.cardDataArray];
    return containerView;
}

# pragma mark - 初始化页面界面方法

- (void)createViews {
    [self addBackgroundImageView];
    [self addHeadScrollView];
    [self addHead2View];
    [self addScrollView];
    [self addPageControl];
}

- (void)addBackgroundImageView {
    self.backgroundImgView = [[UIImageView alloc]init];
    self.backgroundImgView.image = [UIImage imageNamed:@"cloudy"];
    [self.view addSubview:self.backgroundImgView];
    [self.backgroundImgView setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.backgroundImgView attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.backgroundImgView attribute:NSLayoutAttributeBottom multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.backgroundImgView attribute:NSLayoutAttributeLeading multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.backgroundImgView attribute:NSLayoutAttributeTrailing multiplier:1.0f constant:0.0f]];
}

- (void)addHeadScrollView {
    //添加头部scrollview
    self.headScrollView = [[UIScrollView alloc]init];
    //self.headScrollView.backgroundColor = [UIColor yellowColor];
    self.headScrollView.clipsToBounds = NO;//超出部分不隐藏
    self.headScrollView.pagingEnabled = YES;//整页平移开启
    self.headScrollView.alwaysBounceVertical = NO;//不允许垂直拖动
    self.headScrollView.showsHorizontalScrollIndicator = NO;//隐藏水平滑竿
    [self.view addSubview:self.headScrollView];
    [self.headScrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    //这个top和height约束要依据每个手机的型号不同来判别
    NSString *phoneType = [Global iphoneType];
    NSLog(@"获取的手机型号是：%@", phoneType);
    
    if ([phoneType isEqualToString:@"x"]) {
        [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.headScrollView attribute:NSLayoutAttributeTop multiplier:1.0f constant:0.0f]];
        [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headScrollView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:134.0f]];
    }else if ([phoneType isEqualToString:@"6p"]) {
        [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.headScrollView attribute:NSLayoutAttributeTop multiplier:1.0f constant:-20.0f]];
        [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headScrollView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:94.0f]];
    }
    
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.headScrollView attribute:NSLayoutAttributeLeading multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.headScrollView attribute:NSLayoutAttributeTrailing multiplier:1.0f constant:0.0f]];
    
    //给headscrollview添加第一个子控件
    self.headerView = [HeadView createViewFromXIBWithInfo];
    [self.headScrollView addSubview:self.headerView];
    [self.headerView setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headScrollView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.headerView attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f]];
    [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headScrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.headerView attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f]];
    
    [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headScrollView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.headerView attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]];
    
    [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headerView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.headScrollView attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];

    //给headscrollview添加第二个子控件
    self.headerView_2 = [HeadView createViewFromXIBWithInfo];
    self.headerView_2.temperatureLbl.text = @"31°c";
    self.headerView_2.locationLbl.text = @"Hong Kong>";
    [self.headScrollView addSubview:self.headerView_2];
    [self.headerView_2 setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headScrollView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.headerView_2 attribute:NSLayoutAttributeHeight multiplier:1.0f constant:0.0f]];
    [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headScrollView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.headerView_2 attribute:NSLayoutAttributeWidth multiplier:1.0f constant:0.0f]];
    
    [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headScrollView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.headerView_2 attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]];
    
    [self.headScrollView addConstraint:[NSLayoutConstraint constraintWithItem:self.headerView_2 attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.headScrollView attribute:NSLayoutAttributeCenterX multiplier:3.0f constant:0.0f]];
    
    [self.headScrollView layoutIfNeeded];//为了获取正确的frame
    self.headScrollView.contentSize = CGSizeMake(self.headScrollView.frame.size.width * 2, self.scrollView.frame.size.height);//设置ScrollView的contentsize
    
    //给Headscrollview的contentview添加点击跳转页面的事件
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headviewTapped)];
    [self.headerView addGestureRecognizer:tap];
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headview_2Tapped)];
    [self.headerView_2 addGestureRecognizer:tap2];
}

- (void)addHead2View {
    //添加头部2view
    self.header2View = [Head2View createViewFromXIBWithInfo];
    //self.header2View.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:self.header2View];
    [self.header2View setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.header2View attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.header2View attribute:NSLayoutAttributeLeading multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.headerView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.header2View attribute:NSLayoutAttributeTop multiplier:1.0f constant:-30.0f]];
    [self.header2View addConstraint:[NSLayoutConstraint constraintWithItem:self.header2View attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:50.0f]];
    
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(header2ViewTapped)];
    [self.header2View addGestureRecognizer:tap3];
}

- (void)addScrollView {
    self.scrollView = [[UIScrollView alloc]init];
    self.scrollView.backgroundColor = [UIColor clearColor];
    self.scrollView.clipsToBounds = NO;//超出部分不隐藏
    self.scrollView.pagingEnabled = YES;//整页平移开启
    self.scrollView.alwaysBounceVertical = NO;//不允许垂直拖动
    self.scrollView.showsHorizontalScrollIndicator = NO;//隐藏水平滑竿
    [self.view addSubview:self.scrollView];
    [self.scrollView setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    //竖直方向
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.header2View attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeTop multiplier:1.0f constant:-10.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeBottom multiplier:1.0f constant:30.0f]];
    
    //水平方向
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeLeading multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.scrollView attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
}

- (void)addPageControl {
    self.pageControl = [[UIPageControl alloc] init];
    
    if (![Global getToken]) {
        self.pageControl.numberOfPages = 3;
    }else {
        self.pageControl.numberOfPages = 4;
    }
    self.pageControl.currentPage = 0;
    self.pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:55/255.0f green:173/255.0f blue:158/255.0f alpha:1.0f];
    self.pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
    [self.view addSubview:self.pageControl];
    [self.pageControl setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.pageControl attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.pageControl attribute:NSLayoutAttributeBottom multiplier:1.0f constant:20.0f]];
    [self.pageControl addConstraint:[NSLayoutConstraint constraintWithItem:self.pageControl attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:30.0f]];
    [self.pageControl addConstraint:[NSLayoutConstraint constraintWithItem:self.pageControl attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:20.0f]];
}

#pragma mark - 点击事件

- (void)headviewTapped {
    NSLog(@"第一个被点击了");
    WeatherViewController *weatherVC = [WeatherViewController new];
    [self presentViewController:weatherVC animated:YES completion:nil];
}

- (void)headview_2Tapped {
    NSLog(@"第二个被点击了");
    WeatherViewController *weatherVC = [WeatherViewController new];
    [self presentViewController:weatherVC animated:YES completion:nil];
}

- (void)header2ViewTapped {
    NSLog(@"下面的header被点击了");
    //[self.scrollView setContentOffset:CGPointMake(self.view.frame.size.width * 3, 0) animated:YES];
    for (int i = 0; i < self.scrollView.subviews.count; i++) {
        if ([self.scrollView.subviews[i] isKindOfClass:[ContainerView class]]) {
            ContainerView *containerView = (ContainerView *)self.scrollView.subviews[i];
            
            //判断一共有几个页面的不同情况
            if (self.scrollView.subviews.count == 3) {
                if ([containerView.name isEqualToString:@"container3"]) {
                    [containerView resetCardDatas];
                    
                    [self.scrollView setContentOffset:CGPointMake(containerView.frame.origin.x, 0) animated:YES];
                }
            }else {
                if ([containerView.name isEqualToString:@"container4"]) {
                    [containerView resetCardDatas];
                    
                    [self.scrollView setContentOffset:CGPointMake(containerView.frame.origin.x, 0) animated:YES];
                }
            }
        }
    }
}

#pragma mark - scrollview delegate 为了pagecontrol

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    int page = self.scrollView.contentOffset.x / self.scrollView.frame.size.width;
    
    // 设置页码
    self.pageControl.currentPage = page;
}

#pragma mark - 网络请求方法

- (void)requestForCurtainStatus {
    NSURL *url = [NSURL URLWithString:@"http://192.168.98.95:8099/api/getDevicePropertyValue"];
    NSMutableURLRequest *mRequest = [NSMutableURLRequest requestWithURL:url];
    mRequest.HTTPMethod = @"POST";
    NSArray *deviceid_Array = @[@"5a40624802ca8a43eeaff1e8"];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:deviceid_Array, @"device_ids", nil];
    NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil ];
    mRequest.HTTPBody = data;
    [mRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:mRequest completionHandler:
                                      ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                                          
                                          if (error) {
                                              NSLog(@"error是:%@", error);
                                              return ;
                                          }
                                        
                                          NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
                                          //NSLog(@"response是:%@", response);
                                          
                                          NSError *jsonError;
                                          NSDictionary *dataDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error: &jsonError];
                                          
                                          if (jsonError) {
                                              NSLog(@"数据转换出错了，jsonError是：%@", jsonError);
                                              return;
                                          }
                                          
                                          NSInteger code = [[dataDic objectForKey:@"code"] integerValue];
                                          if (code == 0) {
                                              NSArray *resultArray = [dataDic objectForKey:@"result"];
                                              NSDictionary *tempDic = resultArray[0];
                                              
                                              NSInteger code2 = [[tempDic objectForKey:@"code"] integerValue];
                                              if (code2 == 101) {
                                                  NSArray *valueArray = [tempDic objectForKey:@"value"];
                                                  NSDictionary *tempDic2 = valueArray[0];
                                                  NSNumber *valueNumber = [tempDic2 objectForKey:@"value"];
                                                  NSInteger valueInt = [valueNumber integerValue];
                                                  NSLog(@"最后获取到的valueInt是：%ld", (long)valueInt);
                                                  
                                                  //注册通知中心把值传出去
                                                  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
                                                  [center postNotificationName:@"notificationName" object:@(valueInt)];
                                              }else {
                                                  NSLog(@"第二个code不是101，是:%ld", (long)code2);
                                              }
                                          }else {
                                              NSLog(@"第一个code不是0，是：%ld", (long)code);
                                              //显示提示错误的hud
                                          }
                                      }];
    [dataTask resume];
}

#pragma mark - 通知中心接收处理方法
/*
- (void)dealWithBtnClickEvent {
    NSLog(@"代理方法的内容真的在执行");
    
    SaoMaViewController *saoMaVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"saoMaVC"];
    [self presentViewController:saoMaVC animated:YES completion:nil];
}
 */

- (void)dealLoginNotification:(NSNotification *)notification{
    NSLog(@"登录通知代理方法的内容执行了");
    NSString *token = notification.object;
    NSLog(@"通知收到的token是：%@", token);
    
    
    //刷新界面，进入4摞卡牌
    [self initCardDatasForFourPages];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self reloadContainers];
    });
}

- (void)dealTurnPageNotification {
    NSLog(@"进入了处理跳转页面的通知方法");
    
    SaoMaViewController *saoMaVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"saoMaVC"];
    [self presentViewController:saoMaVC animated:YES completion:nil];
}

#pragma mark - 水平方向card数据内容的初始化

- (void)initCardDatasForThreePages {
    ContainerModel *containerModel1 = [ContainerModel new];
    containerModel1.name = @"container1";
    containerModel1.cardDataArray = [NSMutableArray arrayWithObjects:[[CardData alloc] initWithXibName:@"CardView_Contactus"], [[CardData alloc] initWithXibName:@"TermsOfServiceView"], nil];
    
    ContainerModel *containerModel2 = [ContainerModel new];
    containerModel1.name = @"container2";
    containerModel2.cardDataArray = [NSMutableArray arrayWithObjects:[[CardData alloc] initWithXibName:@"LoginRegisterView2"], nil];
    
    ContainerModel *containerModel3 = [ContainerModel new];
    containerModel3.name = @"container3";
    containerModel3.cardDataArray = [NSMutableArray arrayWithObjects:[[CardData alloc] initWithXibName:@"YiJiView"], [[CardData alloc] initWithXibName:@"CardView_1_1"], [[CardData alloc] initWithXibName:@"GreenTipsView"], [[CardData alloc] initWithXibName:@"BeautyTipsView"], [[CardData alloc] initWithXibName:@"SaoMaView"], nil];
    
    [self.containerArray removeAllObjects];
    [self.containerArray addObject:containerModel1];
    [self.containerArray addObject:containerModel2];
    [self.containerArray addObject:containerModel3];
}

- (void)initCardDatasForFourPages {
    ContainerModel *containerModel1 = [ContainerModel new];
    containerModel1.name = @"container1";
    containerModel1.cardDataArray = [NSMutableArray arrayWithObjects:[[CardData alloc] initWithXibName:@"CardView_Contactus"], [[CardData alloc] initWithXibName:@"TermsOfServiceView"], nil];
    
    ContainerModel *containerModel2 = [ContainerModel new];
    containerModel1.name = @"container2";
    containerModel2.cardDataArray = [NSMutableArray arrayWithObjects:[[CardData alloc] initWithXibName:@"AirConditionerView"], [[CardData alloc] initWithXibName:@"CardView_1_2"], [[CardData alloc] initWithXibName:@"WindowView"], nil];
    
    ContainerModel *containerModel3 = [ContainerModel new];
    containerModel3.name = @"container3";
    containerModel3.cardDataArray = [NSMutableArray arrayWithObjects:[[CardData alloc] initWithXibName:@"ChangeInformationView"], nil];
    
    ContainerModel *containerModel4 = [ContainerModel new];
    containerModel4.name = @"container4";
    containerModel4.cardDataArray = [NSMutableArray arrayWithObjects:[[CardData alloc] initWithXibName:@"YiJiView"], [[CardData alloc] initWithXibName:@"CardView_1_1"], [[CardData alloc] initWithXibName:@"GreenTipsView"], [[CardData alloc] initWithXibName:@"BeautyTipsView"], [[CardData alloc] initWithXibName:@"SaoMaView"], nil];
    
    [self.containerArray removeAllObjects];
    [self.containerArray addObject:containerModel1];
    [self.containerArray addObject:containerModel2];
    [self.containerArray addObject:containerModel3];
    [self.containerArray addObject:containerModel4];
}

#pragma mark - uigesturerecognizer代理事件

- (void)tapCancelEvent {
    [self.view endEditing:YES];
}
@end
